package com.hnevc.scrollviewdedmo;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    //定义TAG标记
    public static final String TAG ="MainActivity ";

    //声明变量
    SwipeRefreshLayout swipeRefreshLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //变量赋值为控件
        swipeRefreshLayout= (SwipeRefreshLayout) findViewById(R.id.id_swiperefresh);

        //下拉刷新控件的事件设置
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

            @Override
            public void onRefresh() {
                Log.e(TAG,"onRefresh:");
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(3000);//模拟耗时操作
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                //表示刷新完成
                                swipeRefreshLayout.setRefreshing(false);
                            }
                        });

                    }
                }).start();

            }
        });
    }
}

